﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using ChangDiTools.Tool;
using System.Collections.Generic;
using System.Linq;
namespace ChangDiTools.Demo {
    public class HightestPoints {
        [CommandMethod("HightestPoints")]
        public static void GetHightestPoints() {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction()) {
                List<DBPoint> pts = db.GetEntsInModelSpace<DBPoint>();
                List<Point3d> heightestPoints = (from p in pts
                                                 orderby p.Position.Z descending
                                                 select p.Position).Take(100).ToList();
                for (int i = 0; i < heightestPoints.Count; i++)
                {
                    ed.WriteMessage($"\n{i}:\t {heightestPoints[i].Z.ToString("f4")}");
                }
                tr.Commit();
            }
        }
    }
}
